package com.zxy.supplier_system.server.entity

import jakarta.persistence.*
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import java.time.OffsetDateTime

/**
 * 卖场内部码
 */
@Entity
@Table(
    uniqueConstraints = [
        UniqueConstraint(
            name = "index_union_id",
            columnNames = ["code", "goods_id","market_id"]
        ),
    ]
)
@EntityListeners(AuditingEntityListener::class)
class MarketInternalGoodsCode {


    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    var id:Int? = null

    /**
     * 内部码
     */
    lateinit var code: String

    /**
     * 对应的商品
     */
    @ManyToOne
    @JoinColumn
    lateinit var goods: Goods

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn
    lateinit var market: Market

    @CreatedDate
    lateinit var createdDateTime: OffsetDateTime

}